﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using Jb.Common.Extensions;

namespace Jb.Web.Utility
{
    public class ConfigReader
    {
        private static String GetAppSettingsValue(String key)
        {
            return ConfigurationManager.AppSettings[key];
        }        
        public static String SmtpHost
        {
            get
            {
                return GetAppSettingsValue("SmtpHost");
            }
        }
        /// <summary>
        /// Get the Configuration Value for SMTP port. If not specified then retuns a default value of 25
        /// </summary>
        public static int SmtpPort
        {
            get
            {
                int port = 0;
                String paramValue = GetAppSettingsValue("SmtpPort");
                int.TryParse(paramValue, out port);
                return port == 0 ? 25 : port;
            }
        }

        public static String SmtpFromEmail
        {
            get
            {
                return GetAppSettingsValue("SmtpFromEmail");
            }
        }

        public static String SupportEmail
        {
            get
            {
                return GetAppSettingsValue("SupportEmail");
            }
        }
        public static String ErrorEmail
        {
            get
            {
                return GetAppSettingsValue("ErrorEmail");
            }
        }
        public static String AdminEmail
        {
            get
            {
                return GetAppSettingsValue("AdminEmail");
            }
        }
        public static String SiteName
        {
            get
            {
                return GetAppSettingsValue("SiteName");
            }
        }
        public static String JSCalendarDateFormat
        {
            get
            {
                return GetAppSettingsValue("JSCalendarDateFormat");
            }
        }
        public static String CSharpCalendarDateFormat
        {
            get
            {
                return GetAppSettingsValue("CSharpCalendarDateFormat");
            }
        }

        public static String LuceneSavedStateName
        {
            get
            {
                return GetAppSettingsValue("LuceneSavedStateName");
            }
        }
        public static String LuceneIndexDirectory
        {
            get
            {
                return GetAppSettingsValue("LuceneIndexDirectory");
            }
        }
        /// <summary>
        /// Gets or Sets the MaxNumber OfProductImages
        /// Default Value is 4 If noting is set in the Configuration
        /// </summary>
        public static int MaxNumberOfProductImages
        {
            get
            {
                int count = 0;
                String paramValue = GetAppSettingsValue("MaxNumberOfProductImages");
                count = paramValue.ToInt();
                return count <= 0 ? 4 : count; 
            }
        }
        public static int MaxNumberLogo
        {
            get
            {
                int count = 0;
                String paramValue = GetAppSettingsValue("MaxNumberLogo");
                count = paramValue.ToInt();
                return count <= 0 ? 1 : count;
            }
        }
        public static int UserGroupIDOfJobSeeker
        {
            get
            {
                String paramValue = GetAppSettingsValue("UserGroupIDOfJobSeeker");
                return paramValue.ToInt();
            }
        }
        public static int UserGroupIDOfAdmin
        {
            get
            {
                String paramValue = GetAppSettingsValue("UserGroupIDOfAdmin");
                return paramValue.ToInt();
            }
        }
        public static int UserGroupIDOfCompanyAdmin
        {
            get
            {
                String paramValue = GetAppSettingsValue("UserGroupIDOfCompanyAdmin");
                return paramValue.ToInt();
            }
        }
        public static int UserGroupIDOfCompanyUser
        {
            get
            {
                String paramValue = GetAppSettingsValue("UserGroupIDOfCompanyUser");
                return paramValue.ToInt();
            }
        }
        public static String CurrencyCode
        {
            get
            {
                String paramValue = GetAppSettingsValue("CurrencyCode");
                if (paramValue.IsEmpty())
                    return "Tk";

                return paramValue;
            }
        }

        public static int AboutUs
        {
            get
            {
                String paramValue = GetAppSettingsValue("AboutUs");
                return paramValue.ToInt();
            }
        }

        public static int OurServices
        {
            get
            {
                String paramValue = GetAppSettingsValue("OurServices");
                return paramValue.ToInt();
            }
        }

        public static int FAQ
        {
            get
            {
                String paramValue = GetAppSettingsValue("FAQ");
                return paramValue.ToInt();
            }
        }

        public static int ContactUs
        {
            get
            {
                String paramValue = GetAppSettingsValue("ContactUs");
                return paramValue.ToInt();
            }
        }

        public static int PageSize
        {
            get
            {
                String paramValue = GetAppSettingsValue("PageSize");
                if (paramValue.ToInt() > 0)
                    return paramValue.ToInt();
                return 10;
            }
        }
        /// <summary>
        /// Determines How Many Products can be compared at a time.
        /// </summary>
        public static int MaxNoOfProductsCanBeCompare
        {
            get
            {
                String paramValue = GetAppSettingsValue("MaxNoOfProductsCanBeCompare");
                if (paramValue.ToInt() > 0)
                    return paramValue.ToInt();
                return 3;
            }
        }
        public static int PageSizeOfCompanyJobList
        {
            get
            {
                String paramValue = GetAppSettingsValue("PageSizeOfCompanyJobList");
                if (paramValue.ToInt() > 0)
                    return paramValue.ToInt();
                return 10;
            }
        }
        public static int NumberOfRowsInCategorySelection
        {
            get
            {
                String paramValue = GetAppSettingsValue("NumberOfRowsInCategorySelection");
                if (paramValue.ToInt() > 0)
                    return paramValue.ToInt();
                return 15;
            }
        }
        public static String DefaultJobTemplatePath
        {
            get
            {
                String paramValue = GetAppSettingsValue("DefaultJobTemplatePath");
                if (paramValue.IsNullOrEmpty())
                    throw new Exception("DefaultJobTemplatePath is not set in the AppSettings.conf");

                return paramValue;
            }
        }
        public static float CompanyLogoAspectRatio
        {
            get
            {
                String paramValue = GetAppSettingsValue("CompanyLogoAspectRatio");
                if (paramValue.ToFloat() > 0)
                    return paramValue.ToFloat();
                return (float)3.175;
            }
        }
        public static float JobSeekerPhotoAspectRatio
        {
            get
            {
                String paramValue = GetAppSettingsValue("JobSeekerPhotoAspectRatio");
                if (paramValue.ToFloat() > 0)
                    return paramValue.ToFloat();
                return (float) 1.333;
            }
        }
        public static bool SimulateMobileRequest
        {
            get
            {
                String value = GetAppSettingsValue("SimulateMobileRequest");
                return value.ToBoolean();
            }
        }

        /// <summary>
        /// This is obsolete and moved to Site configuration
        /// </summary>
        //public static bool AutoSubscribeToFreePackage
        //{
        //    get
        //    {
        //        String value = GetAppSettingsValue("AutoSubscribeToFreePackage");
        //        return value.ToBoolean();
        //    }
        //}

        public static int DefaultIndustryTypeID
        {
            get
            {
                return GetAppSettingsValue("DefaultIndustryTypeID").ToInt();
            }
        }

        public static bool SendErrorEmail
        {
            get
            {
                String value = GetAppSettingsValue("SendErrorEmail");
                if (value.IsNullOrEmpty())
                    return true;

                return value.ToBoolean();
            }
        }
    }
}